import { ref } from "vue";
export const registerUser = ref({
    name: "",
    email: "",
    password: "",
    password2: "",
    role: ""
})
export const validatePass2 = (rule, value, callback) => {
    if (value === '') {
        callback(new Error('Please input the password again'))
    } else if (value !== registerUser.value.password) {
        callback(new Error("Two inputs don't match!"))
    } else {
        callback()
    }
}
export  const registerRules = ref({
    name: [
        {
            message: "用户名不能为空...",
            required: true, //必须有
            trigger: 'blur' //离开的时候去校验
        },
        {
            min: 2,
            max: 30,
            message: "长度在2~30个字符",
            trigger: 'blur'
        }
    ],
    email: [
        {
            type: "email",
            message: "Email is incorrect..",
            required: true,
            trigger: 'blur' //离开的时候去校验
        }
    ],
    password: [
        {
            required: true,
            message: "Password cloud not be empty...",
            trigger: 'blur'
        },
        {
            min: 6,
            max: 30,
            message: "Password's length has to be 6 to 30 characters...",
            trigger: 'blur' //离开的时候去校验
        }
    ],
    password2: [
        {
            required: true,
            message: "Password cloud not be empty...",
            trigger: 'blur'
        },
        {
            min: 6,
            max: 30,
            message: "Password's length has to be 6 to 30 characters...",
            trigger: 'blur' //离开的时候去校验
        },
        {
            validator: validatePass2,
            trigger: 'blur'
        }
    ]
})
